<?php
if ( !defined('IN_SITE') ){
	die('Hacking Attemp!');
}
function getOldUrl(){
	 $url='';
	 $base_url= $_SERVER['PHP_SELF'];  
	while(list($key, $value) = each($_GET)){		 
		$url.= !empty($url)?  "&".$key."=".$value : "?".$key."=".$value ;			
	}	
	 
	$tem=substr($url,strlen($url)-1,1);
	if($tem=="="){
		$url=substr($url,0,strlen($url)-1);
	}
	$str=$base_url .$url;	
	return eregi_replace("/vn","",$str);
}	
function redirect($url='') {	 
	print "<script>window.location=\"" . $url . "\";</script>";		
	exit;
}
function alert_redirect($url='',$mess='') {	 
	print "<script>alert(\"".$mess."\");window.location=\"" . $url . "\";</script>";		
	exit;
}
function rand_string($size){
   $string = "aAbBcCdDeEeFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVmWxXzYyZ";
   $rand_str = "";
   for ($i=0; $i<$size; $i++)
   {
	   $rand_str .= substr($string, rand(0, strlen($string)-1), 1);
   }
   return $rand_str;
}
function chgInd($str){
	$str = mb_strtolower($str,"utf8") ;
	$strOld = array("1","0"," ","2","3","4","5","6","7","8","9","''","&quot;","-","(",")","@","!","#","$","%","^","&amp;","*","[","]","{","}",",",".","/",":",";","a","b","c","d","đ","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","á","à","ả","ã","ạ","ó","ò","ỏ","õ","ọ","ô","ố","ồ","ổ","ỗ","ộ","ơ","ớ","ờ","ở","ỡ","ợ","ú","ù","ủ","ũ","ụ","ư","ứ","ừ","ử","ữ","ự","í","ì","ỉ","ĩ","ị","â","ấ","ầ","ẩ","ẫ","ậ","ă","ắ","ằ","ẳ","ẵ","ặ","é","è","ẻ","ẽ","ẹ","ê","ế","ề","ể","ễ","ệ","ý","ỳ","ỷ","ỹ","ỵ","'") ;

	$strNew = array("1D","1C","0W","1E","1F","1G","1H","1I","1J","1K","1L","13","0Y","19","14","15","1S","0X","0Z","10","11","6Z","12","16","6Z","6Z","6Z","6Z","18","1A","1B","1M","1N","1T","2T","2V","2X","2Z","31","3P","3R","3T","3V","47","49","4B","4D","4F","4H","5H","5J","5L","5N","5P","5R","6F","6H","6J","6L","6X","1V6Z","1X6Z","1Z6Z","216Z","236Z","4J6Z","4L6Z","4N6Z","4P6Z","4R6Z","4T6Z","4V6Z","4X6Z","4Z6Z","516Z","536Z","55","576Z","596Z","5B6Z","5D6Z","5F6Z","5T6Z","5V6Z","5X6Z","5Z6Z","616Z","63","656Z","676Z","696Z","6B6Z","6D6Z","3X","3Z","41","43","45","2H6Z","2J6Z","2L6Z","2N6Z","2P6Z","2R6Z","256Z","276Z","296Z","2B6Z","2D6Z","2F6Z","336Z","356Z","376Z","396Z","3B6Z","3D6Z","3F6Z","3H6Z","3J6Z","3L6Z","3N6Z","6N6Z","6P6Z","6R6Z","6T6Z","6V","13") ;
	
	for($i=0;$i<count($strOld);$i++){
		$str = str_replace($strOld[$i],$strNew[$i],$str) ;
	}
	return $str ;
}
/***************************************************************************/
function encrypt($str){
	for($i = 0; $i <2; $i ++){
		$str = base64_encode(base64_encode($str));
	}
	$str=rand_string(5).$str;
	return $str;	
}
function decrypt($str){
	$str=substr($str,5,strlen($str));		
	for($i = 0; $i < 2; $i ++){
		$str = base64_decode(base64_decode($str));
	}
	
	return $str;
}
//Generate the pageination of the list by 3
function g3_pagination($base_url, $num_items, $per_page, $start_item, $pos_var = 'start' , $add_prevnext_text = '') {
	$page_string = '';
	$total_pages = ceil($num_items/$per_page);

	if ( $total_pages > 1 ) {
		$on_page = floor($start_item / $per_page) + 1;
		if ( $total_pages > 10 ) {
			$init_page_max = ( $total_pages > 3 ) ? 3 : $total_pages;
			for($i = 1; $i < $init_page_max + 1; $i++) {
				$page_string .= ( $i == $on_page ) ? '<b>' . $i . '</b>' : '<a href="' . ($base_url . "&amp;$pos_var=" . ( ( $i - 1 ) * $per_page ) ) . '" class="ca">' . $i . '</a>';
				if ( $i <  $init_page_max ) {
					$page_string .= ", ";
				}
			}
			if ( $total_pages > 3 ) {
				if ( $on_page > 1  && $on_page < $total_pages ) {
					$page_string .= ( $on_page > 5 ) ? ' ... ' : ', ';
					$init_page_min = ( $on_page > 4 ) ? $on_page : 5;
					$init_page_max = ( $on_page < $total_pages - 4 ) ? $on_page : $total_pages - 4;
					for($i = $init_page_min - 1; $i < $init_page_max + 2; $i++) {
						$page_string .= ($i == $on_page) ? '<b>' . $i . '</b>' : '<a href="' . ($base_url . "&amp;$pos_var=" . ( ( $i - 1 ) * $per_page ) ) . '" class="ca">' . $i . '</a>';
						if ( $i <  $init_page_max + 1 ) {
							$page_string .= ', ';
						}
					}
					$page_string .= ( $on_page < $total_pages - 4 ) ? ' ... ' : ', ';
				}
				else {
					$page_string .= ' ... ';
				}
	
				for($i = $total_pages - 2; $i < $total_pages + 1; $i++) {
					$page_string .= ( $i == $on_page ) ? '<b>' . $i . '</b>'  : '<a href="' . ($base_url . "&amp;$pos_var=" . ( ( $i - 1 ) * $per_page ) ) . '" class="ca">' . $i . '</a>';
					if ( $i <  $total_pages ) {
						$page_string .= ", ";
					}
				}
			}
		}
		else {
			for($i = 1; $i < $total_pages + 1; $i++) {
				$page_string .= ( $i == $on_page ) ? '<b>' . $i . '</b>' : '<a href="' . ($base_url . "&amp;$pos_var=" . ( ( $i - 1 ) * $per_page ) ) . '" class="ca">' . $i . '</a>';
				if ( $i <  $total_pages ) {
					$page_string .= ', ';
				}
			}
		}
	
		if ( $add_prevnext_text ) {
			 list ($lang_page, $lang_prev, $lang_next) = split ('//', $add_prevnext_text);			 
			if ( $on_page > 1 ) {
				$page_string = ' <a href="' . ($base_url . "&amp;$pos_var=" . ( ( $on_page - 2 ) * $per_page ) ) . '" class="ca">' . $lang_prev . '</a>&nbsp;&nbsp;' . $page_string;
			}
			if ( $on_page < $total_pages ) {
				$page_string .= '&nbsp;&nbsp;<a href="' . ($base_url . "&amp;$pos_var=" . ( $on_page * $per_page ) ) . '" class="ca">' . $lang_next . '</a>';
			}
			 
			//$page_string = $lang_page . $page_string;
			$page_string = $lang_page .$on_page ." of  " .$total_pages." &nbsp;&nbsp;&nbsp;&nbsp;". $page_string;
		}
	}
	return $page_string;
}
function pagination($base_url, $num_items, $per_page, $start_item, $pos_var = 'start' , $add_prevnext_text = '') {
	$page_string = '';
	$total_pages = ceil($num_items/$per_page);

	if ( $total_pages > 1 ) {
		$on_page = floor($start_item / $per_page) + 1;
		if ( $total_pages > 10 ) {
			$init_page_max = ( $total_pages > 3 ) ? 3 : $total_pages;
			for($i = 1; $i < $init_page_max + 1; $i++) {
				$page_string .= ( $i == $on_page ) ? '<b>' . $i . '</b>' : '<a href="' . ($base_url . "/" . ( ( $i - 1 ) * $per_page ) ) . '">' . $i . '</a>';
				if ( $i <  $init_page_max ) {
					$page_string .= ", ";
				}
			}
			if ( $total_pages > 3 ) {
				if ( $on_page > 1  && $on_page < $total_pages ) {
					$page_string .= ( $on_page > 5 ) ? ' ... ' : ', ';
					$init_page_min = ( $on_page > 4 ) ? $on_page : 5;
					$init_page_max = ( $on_page < $total_pages - 4 ) ? $on_page : $total_pages - 4;
					for($i = $init_page_min - 1; $i < $init_page_max + 2; $i++) {
						$page_string .= ($i == $on_page) ? '<b>' . $i . '</b>' : '<a href="' . ($base_url . "/" . ( ( $i - 1 ) * $per_page ) ) . '">' . $i . '</a>';
						if ( $i <  $init_page_max + 1 ) {
							$page_string .= ', ';
						}
					}
					$page_string .= ( $on_page < $total_pages - 4 ) ? ' ... ' : ', ';
				}
				else {
					$page_string .= ' ... ';
				}
	
				for($i = $total_pages - 2; $i < $total_pages + 1; $i++) {
					$page_string .= ( $i == $on_page ) ? '<b>' . $i . '</b>'  : '<a href="' . ($base_url . "/" . ( ( $i - 1 ) * $per_page ) ) . '">' . $i . '</a>';
					if ( $i <  $total_pages ) {
						$page_string .= ", ";
					}
				}
			}
		}
		else {
			for($i = 1; $i < $total_pages + 1; $i++) {
				$page_string .= ( $i == $on_page ) ? '<b>' . $i . '</b>' : '<a href="' . ($base_url . "/" . ( ( $i - 1 ) * $per_page ) ) . '">' . $i . '</a>';
				if ( $i <  $total_pages ) {
					$page_string .= ', ';
				}
			}
		}
	
		if ( $add_prevnext_text ) {
			list ($lang_page, $lang_prev, $lang_next) = split ('@', $add_prevnext_text);
			if ( $on_page > 1 ) {
				$page_string = ' <a href="' . ($base_url . "/" . ( ( $on_page - 2 ) * $per_page ) ) . '">' . $lang_prev . '</a>&nbsp;&nbsp;' . $page_string;
			}
			if ( $on_page < $total_pages ) {
				$page_string .= '&nbsp;&nbsp;<a href="' . ($base_url . "/" . ( $on_page * $per_page ) ) . '">' . $lang_next . '</a>';
			}
			$page_string = $lang_page .$on_page ." of  " .$total_pages." &nbsp;&nbsp;&nbsp;&nbsp;". $page_string;
		}
	}
	return $page_string;
}
function message_die($msg_text='',$str='', $err_line='',$err_file='',$sql='') {
	global $db, $debug_mode;

	$sql_store = $sql;

	if ( $debug_mode ) {
		$sql_error = $db->sql_error();

		$debug_text = '';

		if ( $sql_error['message'] != '' ){
			$debug_text .= '<br /><br />SQL Error : ' . $sql_error['code'] . ' ' . $sql_error['message'];
		}

		if ( $sql_store != '' ){
			$debug_text .= "<br /><br />$sql_store";
		}

		if ( $err_line != '' && $err_file != ''){
			$debug_text .= '</br /><br />Line : ' . $err_line . '<br />File : ' . $err_file;
		}
	}else {
		$debug_text = "<br /><br />Contact webmaster for notice, please!";
	}

	$msg_text = '<b>' . $msg_text . '</b>' . $debug_text;
	echo $msg_text ." tritigi<br>". $sql ;
	die();
}
function check_email($sEmail) {
	// Regex of valid characters
	$sChars = "^[A-Za-z0-9-]+@([A-Za-z][A-Za-z0-9-]{1,62})(\.[A-Za-z][A-Za-z0-9-]{1,62})+$";

	// Check to make sure it is valid
	if ( !ereg("$sChars", $sEmail) ){
		return false;
	}

	return true;
}
function getCate($id=0){
 global $db,$template;
 
	$sql="select catID,cat_Name from vb_category where cat_active=1 and cat_Level=1";
	
	if($id){
	   $sql.=" and catID=".$id;   
		
		 if(!$result=$db->sql_query($sql)){
			message_die("Couldn't run the sql query!!!","",__LINE__,__FILE__,$sql);
		 }
		 $sql_data = $db->sql_fetchrow($result);
		 
		 return $sql_data["cat_Name"];
	  }
  
	if(!$result=$db->sql_query($sql)){
		message_die("Couldn't run the sql query!!!", "", __LINE__, __FILE__, $sql);
	}
	
	$cat_count=$db->sql_numrows($result);
	$cat_data=$db->sql_fetchrowset($result);
	
	for($i=0;$i<$cat_count;$i++){
		$template->assign_block_vars("catrow", array(			
			'catValue'		=> $cat_data[$i]["catID"],	
			'catCaption'   	=> $cat_data[$i]["cat_Name"]		
			));
	}
  unset($cat_data);
}
function getypCate($id=0){
	global $db,$template;
 
	$sql="select catID,cat_Name from vb_ypcategory where cat_active=1 and cat_Level=1";
	
	if($id){
	   $sql.=" and catID=".$id;   
		
		 if(!$result=$db->sql_query($sql)){
			message_die("Couldn't run the sql query!!!","",__LINE__,__FILE__,$sql);
		 }
		 $sql_data = $db->sql_fetchrow($result);
		 
		 return $sql_data["cat_Name"];
	  }
  
	if(!$result=$db->sql_query($sql)){
		message_die("Couldn't run the sql query!!!", "", __LINE__, __FILE__, $sql);
	}
	
	$cat_count=$db->sql_numrows($result);
	$cat_data=$db->sql_fetchrowset($result);
	
	for($i=0;$i<$cat_count;$i++){
		$template->assign_block_vars("catrow", array(			
			'catValue'		=> $cat_data[$i]["catID"],	
			'catCaption'   	=> $cat_data[$i]["cat_Name"]		
			));
	}
  unset($cat_data);
}
function getBussType($busID=0){
	global $template, $db;	
	$sql="select * from vb_businesstype";

	if($busID){
		$sql.=" where id=".$busID;   
		
		if(!$result=$db->sql_query($sql)){
			message_die("Couldn't run the sql query!!!","",__LINE__,__FILE__,$sql);
		}
		 $sql_data = $db->sql_fetchrow($result);
		 
		 return $sql_data["c_name"];
	}
  
	if(!$result=$db->sql_query($sql)){
		message_die("Couldn't run the sql query!!!","",__LINE__,__FILE__,$sql);
	}
	$dep_count=$db->sql_numrows($result);
	$dep_data=$db->sql_fetchrowset($result);	
	$db->sql_freeresult($result);

	for($i=0;$i<$dep_count;$i++){
		$template->assign_block_vars("busType",array(
			"bvalue"     => $dep_data[$i]["id"],
			"bcaption"  => $dep_data[$i]["c_name"]	
		)) ;
	}
	unset($dep_data);
	return true;
}
function getContry($cID=0){
 global $template, $db;	
  $sql="select * from vb_country";

   if($cID){
   $sql.=" where id=".$cID;   
    
     if(!$result=$db->sql_query($sql)){
  		message_die("Couldn't run the sql query!!!","",__LINE__,__FILE__,$sql);
 	 }
	 $sql_data = $db->sql_fetchrow($result);
	 
	 return html_entity_decode($sql_data["c_name"]);
  }
  
  if(!$result=$db->sql_query($sql)){
  	message_die("Couldn't run the sql query!!!","",__LINE__,__FILE__,$sql);
  }
  $dep_count=$db->sql_numrows($result);
  $dep_data=$db->sql_fetchrowset($result);	
  $db->sql_freeresult($result);
  for($i=0;$i<$dep_count;$i++){
   	$template->assign_block_vars("country",array(
	 "bvalue"     => $dep_data[$i]["id"],
	 "bcaption"  => html_entity_decode($dep_data[$i]["c_name"])
	)) ;
  }
    unset($dep_data);
  return true;
}
function getState($cID=0){
 global $template, $db;	
  $sql="select * from vb_city";

   if($cID){
   $sql.=" where id=".$cID;   
    
     if(!$result=$db->sql_query($sql)){
  		message_die("Couldn't run the sql query!!!","",__LINE__,__FILE__,$sql);
 	 }
	 $sql_data = $db->sql_fetchrow($result);
	 
	 return html_entity_decode($sql_data["c_name"]);
  }
  
  if(!$result=$db->sql_query($sql)){
  	message_die("Couldn't run the sql query!!!","",__LINE__,__FILE__,$sql);
  }
  $dep_count=$db->sql_numrows($result);
  $dep_data=$db->sql_fetchrowset($result);	
  $db->sql_freeresult($result);
  for($i=0;$i<$dep_count;$i++){
   	$template->assign_block_vars("countryselect",array(
	 "bvalue"     => html_entity_decode($dep_data[$i]["zip"]),
	 "bcaption"  => html_entity_decode($dep_data[$i]["c_name"])
	)) ;
  }
    unset($dep_data);
  return true;
}
function getState1($cID=0){
 global $template, $db;	
  $sql="select distinct(c.zip),c_name from vb_city c inner join
 vb_memberprofile m on c.zip=m.zip inner join 
 vb_products p on m.memID=p.memID where p.catID=".$cID;

   
  if(!$result=$db->sql_query($sql)){
  	message_die("Couldn't run the sql query!!!","",__LINE__,__FILE__,$sql);
  }
  $dep_count=$db->sql_numrows($result);
  $dep_data=$db->sql_fetchrowset($result);	
  $db->sql_freeresult($result);
  for($i=0;$i<$dep_count;$i++){
   	$template->assign_block_vars("countryselect",array(
	 "bvalue"     => html_entity_decode($dep_data[$i]["zip"]),
	 "bcaption"  => html_entity_decode($dep_data[$i]["c_name"])
	)) ;
  }
    unset($dep_data);
  return true;
}
function getNumEmployee($emID=0,$lang='en'){
 global $template, $db;	
  $sql="select * from vb_numemployer";
  
   if($emID){
   $sql.=" where id=".$emID;   
    
     if(!$result=$db->sql_query($sql)){
  		message_die("Couldn't run the sql query!!!","",__LINE__,__FILE__,$sql);
 	 }
	 $sql_data = $db->sql_fetchrow($result);
	 
	 switch ($lang) {
	 	case 'cn' : 
	 		return $sql_data["c_name_cn"];
			break ;
		case 'vn' : 
	 		return $sql_data["c_name_vn"];
			break ;
		default : 
	 		return $sql_data["c_name"];
			break ;
	}
  }
  
  if(!$result=$db->sql_query($sql)){
  	message_die("Couldn't run the sql query!!!","",__LINE__,__FILE__,$sql);
  }
  $dep_count=$db->sql_numrows($result);
  $dep_data=$db->sql_fetchrowset($result);	
  $db->sql_freeresult($result);
  for($i=0;$i<$dep_count;$i++){
   	$template->assign_block_vars("numEmploy",array(
	 "bvalue"     => $dep_data[$i]["id"],
	 "bcaption"  => $dep_data[$i]["c_name"]	
	)) ;
  }
  unset($dep_data);
  return true;
}
function getJobTitle($jobID=0){
 global $template, $db;	
 
  $sql="select * from vb_jobtitle";
  if($jobID){
   $sql.=" where id=".$jobID;
     if(!$result=$db->sql_query($sql)){
  		message_die("Couldn't run the sql query!!!","",__LINE__,__FILE__,$sql);
 	 }
	 $sql_data = $db->sql_fetchrow($result);
	 return $sql_data["c_name"];
  }
  if(!$result=$db->sql_query($sql)){
  	message_die("Couldn't run the sql query!!!","",__LINE__,__FILE__,$sql);
  }
  $dep_count=$db->sql_numrows($result);
  $dep_data=$db->sql_fetchrowset($result);	
  $db->sql_freeresult($result);
  for($i=0;$i<$dep_count;$i++){
   	$template->assign_block_vars("jobType",array(
	 "bvalue"     => $dep_data[$i]["id"],
	 "bcaption"  => $dep_data[$i]["c_name"]	
	)) ;
  }
  unset($dep_data);
  return true;
}
function getMainMarket($id=0){
 global $template, $db;	
  $sql="select * from vb_mainmarket";
  if($id){
   $sql.=" where id=".$id;
     if(!$result=$db->sql_query($sql)){
  		message_die("Couldn't run the sql query!!!","",__LINE__,__FILE__,$sql);
 	 }
	 $sql_data = $db->sql_fetchrow($result);
	 return $sql_data["c_name"];
  }
  
  if(!$result=$db->sql_query($sql)){
  	message_die("Couldn't run the sql query!!!","",__LINE__,__FILE__,$sql);
  }
  $dep_count=$db->sql_numrows($result);
  $dep_data=$db->sql_fetchrowset($result);	
  $db->sql_freeresult($result);
  for($i=0;$i<$dep_count;$i++){
   	$template->assign_block_vars("MainMark",array(
	 "bvalue"     => $dep_data[$i]["id"],
	 "bcaption"  => $dep_data[$i]["c_name"]	
	)) ;
  }
  unset($dep_date);
  return true;
}
function repStr($str){
	$strTem = "" ;
	$arr1=explode(",",$str); 
	$sc=sizeof($arr1)-1;
	for($i=0;$i<$sc;$i++){
		if(!empty($arr1[$i])){
			if(!eregi($arr1[$i],$strTem)){
				$strTem= isset($strTem) ? $strTem.",".$arr1[$i] :  $arr1[$i];		
			}
		}
	 }
	 return $strTem;
}
function showCategory($cat='',$lang='vn'){
	global $template, $db;	
	 
	$arr1=explode(",",$cat);
	$c1=sizeof($arr1)-1;
	for($i=0;$i<$c1;$i++){
		if(!empty($arr1[$i])){
		 $where=ereg_replace("-",",",$arr1[$i]);
		 $sql="select cat_Name,cat_Name_cn,cat_Name_vn from vb_ypcategory where catID in (".$where.") order by catID"; 
		 if(!$result=$db->sql_query($sql)){
			message_die("Couldn't run the sql query!!!","",__LINE__,__FILE__,$sql);
		 }
		$cat_count=$db->sql_numrows($result);
		$cat_data=$db->sql_fetchrowset($result);	
		for($j=0;$j<$cat_count;$j++){
			//$catCap= isset($catCap) ? $catCap.">>".$cat_data[$j]["cat_Name"] : $cat_data[$j]["cat_Name"];
			switch ($lang){
				case "cn":
					$catCap= isset($catCap) ? $catCap.">>".$cat_data[$j]["cat_Name_cn"] : $cat_data[$j]["cat_Name_cn"];
					break ;
				case "en":
					$catCap= isset($catCap) ? $catCap.">>".$cat_data[$j]["cat_Name"] : $cat_data[$j]["cat_Name"];
					break ;
				default :
					$catCap= isset($catCap) ? $catCap.">>".$cat_data[$j]["cat_Name_vn"] : $cat_data[$j]["cat_Name_vn"];
			}
		}
		$template->assign_block_vars("catrow",array(
			"catValue"     => $arr1[$i],
			"catCaption"  => $catCap
		)) ;
	  }	
	  unset($catCap);
	} //Efor
	return true;
}
function check_gpc(){
	if (get_magic_quotes_gpc()){
		$gpc = 1;
	}
	else{
		$gpc = 0;
	}
 
    if (is_array($_GET)){
		   while(list($key, $val) = each($_GET)){
				 if (is_array($_GET[$key])){
					   while(list($key2, $val2) = each($_GET[$key]))
					   {
							 if ($gpc){
								 $_GET[$key][$key2] = trim($val2);
							 }
							 else{
								 $_GET[$key][$key2] = addslashes(trim($val2));
							 }
					   }
					   @reset($_GET[$key]);
				 }else{
						if ($gpc){
						   $_GET[$key] = trim($val);
						}else{
						   $_GET[$key] = addslashes(trim($val));
						}
				 }
		   }
	       @reset($_GET);
	  }
          if (is_array($_POST)){
                while( list($key, $val) = each($_POST) ){
                      if ( is_array($_POST[$key]) ){
                            while(list($key2, $val2) = each($_POST[$key])){
								if ($gpc){
	                                 $_POST[$key][$key2] = trim($val2);	
								}
								else{
	                                 $_POST[$key][$key2] = addslashes(trim($val2));	
								}
                            }
                            @reset($_POST[$key]);
                      }
                      else{
					  		if ($gpc){
	                            $_POST[$key] = trim($val);
							}
							else{
	                            $_POST[$key] = addslashes(trim($val));
							}
                      }
                }
                @reset($_POST);
          }

          if (is_array($_COOKIE)){
                while (list($key, $val) = each($_COOKIE)){
                      if (is_array($_COOKIE[$key])){
                            while (list($key2, $val2) = each($_COOKIE[$key])){
								if ($gpc){
	                                 $_COOKIE[$key][$key2] = trim($val2);
								}
								else{
	                                 $_COOKIE[$key][$key2] = addslashes(trim($val2));
								}
                            }
                            @reset($_COOKIE[$key]);
                      }
                      else{
					  		if ($gpc){
	                            $_COOKIE[$key] = trim($val);
							}
							else{
	                            $_COOKIE[$key] = addslashes(trim($val));
							}
                      }
                }
                @reset($_COOKIE);
          }

          if (is_array($_FILES)){
                while (list($key, $val) = each($_FILES)){
                      if (is_array($_FILES[$key])){
                            while (list($key2, $val2) = each($_FILES[$key])){
								if ($gpc){
	                                 $_FILES[$key][$key2] = trim($val2);
								}
								else{
	                                 $_FILES[$key][$key2] = addslashes(trim($val2));
								}
                            }
                            @reset($_FILES[$key]);
                      }
                      else{
					  		if ($gpc){
	                            $_FILES[$key] = trim($val);
							}
							else{
	                            $_FILES[$key] = addslashes(trim($val));
							}
                      }
                }
                @reset($_FILES);
          }
}
function checkSubCat($catArr=array(),$catid=0){
	if(is_array($catArr) && $catid ){
		for($i=0;$i<sizeof($catArr);$i++){
		  if(isset($catArr[$i]["cat_Sub"])&&($catArr[$i]["cat_Sub"]==$catid)){
		  	$catArr=array();
		  	return 1;
		  }
		}
	}
	$catArr=array();
	return 0;
}
function getExpried($strTime=0,$intTime=0){
	//tri: check is OK
	$epriTime = '' ;
	if($strTime){
		if($strTime==4){
		 	$epriTime=date('Y-m-d',strtotime("+1 month",$intTime));
		}else{
			$epriTime=date("Y-m-d",$intTime + ((7*$strTime) * 24 * 60 * 60));
		}
	}
	return $epriTime;	
}
function getSubTitle($id=0,$flag=0){
	global $db,$site_base_href;
	$base_url="index.php?";
	$sql="select cat_Name,catID,cat_Sub from vb_category where catCount>0 and catID=".$id; 
	
	if(!$result=$db->sql_query($sql)){
		message_die("Couldn't run the sql query!!!", "", __LINE__, __FILE__, $sql);
	}	 
	$cat_lv1=$db->sql_fetchrow($result);	
	$title=$cat_lv1["cat_Name"];
	if($flag){
		return $title;
	}
	if($cat_lv1["cat_Sub"]){
		$sql="select cat_Name,catID,cat_Sub from vb_category where catCount>0 and  catID=".$cat_lv1["cat_Sub"]; 
		 if(!$result=$db->sql_query($sql)){
			message_die("Couldn't run the sql query!!!", "", __LINE__, __FILE__, $sql);
		}			 
		$cat_lv2=$db->sql_fetchrow($result);	
		$title='<a href="'.$site_base_href."/".$base_url.'?/catalogs/'.$cat_lv2["catID"].'/'.ereg_replace(" ","_",$cat_lv2["cat_Name"]).'.html&ids=21dbf14c7fa986fdafe8983b21d1c843&lang=us" class="text-header">'. $cat_lv2['cat_Name'].'</a> > '.$title;
		if($cat_lv2["cat_Sub"]){
			$sql="select cat_Name,catID,cat_Sub from vb_category where catCount>0 and  catID=".$cat_lv2["cat_Sub"]; 
			 if(!$result=$db->sql_query($sql)){
				message_die("Couldn't run the sql query!!!", "", __LINE__, __FILE__, $sql);
			}	 
			$cat_lv3=$db->sql_fetchrow($result);
			$title='<a href="'.$site_base_href."/".$base_url.'?/catalogs/'.$cat_lv3["catID"].'/'.ereg_replace(" ","_",$cat_lv3["cat_Name"]).'.html&ids=21dbf14c7fa986fdafe8983b21d1c843&lang=us" class="text-header">'. $cat_lv3['cat_Name'].'</a> > '.$title;		
		}
		
	}
	return $title;
} 
function getSubTitle1($id=0,$flag=0){
	global $db,$site_base_href;
	$base_url="index.php";
	$sql="select cat_Name,catID,cat_Sub from vb_category where catCount>0 and catID=".$id; 
	
	if(!$result=$db->sql_query($sql)){
		message_die("Couldn't run the sql query!!!", "", __LINE__, __FILE__, $sql);
	}	 
	$cat_lv1=$db->sql_fetchrow($result);	
	$title=$cat_lv1["cat_Name"];

	$title='<a href="'.$site_base_href."/".$base_url.'?/manufacturers/'.$id.'/'.ereg_replace(" ","_",$cat_lv1["cat_Name"]).'.html&ids=21dbf14c7fa986fdafe8983b21d1c843&lang=us" class="text-header">'. $cat_lv1["cat_Name"].'</a>';

	if($flag){
		return $title;
	}
	if($cat_lv1["cat_Sub"]){
		$sql="select cat_Name,catID,cat_Sub from vb_category where catCount>0 and  catID=".$cat_lv1["cat_Sub"]; 
		 if(!$result=$db->sql_query($sql)){
			message_die("Couldn't run the sql query!!!", "", __LINE__, __FILE__, $sql);
		}			 
		$cat_lv2=$db->sql_fetchrow($result);	
		$title='<a href="'.$site_base_href."/".$base_url.'?/catalogs/'.$cat_lv2["catID"].'/'.ereg_replace(" ","_",$cat_lv2["cat_Name"]).'.html&ids=21dbf14c7fa986fdafe8983b21d1c843&lang=us" class="text-header">'. $cat_lv2['cat_Name'].'</a> > '.$title;
		if($cat_lv2["cat_Sub"]){
			$sql="select cat_Name,catID,cat_Sub from vb_category where catCount>0 and  catID=".$cat_lv2["cat_Sub"]; 
			 if(!$result=$db->sql_query($sql)){
				message_die("Couldn't run the sql query!!!", "", __LINE__, __FILE__, $sql);
			}	 
			$cat_lv3=$db->sql_fetchrow($result);
			$title='<a href="'.$site_base_href."/".$base_url.'?/catalogs/'.$cat_lv3["catID"].'/'.ereg_replace(" ","_",$cat_lv3["cat_Name"]).'.html&ids=21dbf14c7fa986fdafe8983b21d1c843&lang=us" class="text-header">'. $cat_lv3['cat_Name'].'</a> > '.$title;		
		}
		
	}
	return $title;
} 
function getSupplier($lev=1){
	 global $site_base_href;
	if($lev==1){
		$str="Free Member";
	}elseif($lev==2){
		$str='Silver Supplier';	
		//$str='<img src="'.$site_base_href.'/images/silver_suppliers.gif" border="0">';	
	}elseif($lev==3){
		$str='Gold Supplier';	
		//$str='<img src="'.$site_base_href.'/images/gold_suppliers.gif" border="0">';	
	}elseif($lev==4){
		$str='Premium Supplier';	
		//$str='<img src="'.$site_base_href.'/images/gold_suppliers.gif" border="0">';	
	}
	return $str;

}
function dateformat($strdata=''){
	if(!empty($strdata)){
		$temdate=explode("-",$strdata);
		$strdata=$temdate[2].'-'.$temdate[1].'-'.$temdate[0];		
	}
	return $strdata;
} 
?>